import { Injectable } from '@angular/core';
import { Resolve } from '@angular/router';
import { forkJoin, Observable } from 'rxjs';
import { first } from 'rxjs/operators';
import { HomeService } from '@services/home.service';
import { SingerService } from '@services/singer.service';
import { Banner, HotTag, Singer, SongSheet } from '@services/data-types/common.type';

type HomeDataType = [Banner[], HotTag[], SongSheet[], Singer[]];

@Injectable()
export class HomeResolveService implements Resolve<HomeDataType> {
  constructor(
    private homeService: HomeService,
    private singerService: SingerService
  ) {}
  resolve(): Observable<HomeDataType> {
    return forkJoin(
      this.homeService.getBanner(),
      this.homeService.getHotTags(),
      this.homeService.getPersonalSheetList(),
      this.singerService.getEnteredSinger()
    ).pipe(first());
  }
}
